MODULE ModCoolTot

!!$ This module contains all subroutines for cooling.
!!$ TODO: Move all cooling functions from pisco.F90 into this module.
!!$ Programming conventions are from Nyhoff and Leestma, _Fortran 90 for Scientists and Engineers_, 1997
!!$
!!$  STH: Samuel Harrold

!!$ Declare modules to USE
  USE ModCoolCII
  USE ModCoolOI

!!$ TODO: make other modules for all other cooling routines and USE

!!$ Do not assume undeclared variables
  IMPLICIT NONE



CONTAINS


  
!!$ CalcCoolTot
!!$ This subroutine calculates the cooling of the gas due to all included cooling routines.
!!$ TODO: make all cooling subroutines modules.
!!$ TODO: make J the radiation field gg. Currently using J = gg(158 um)
!!$ Accepts: density, temperature, column density in line of sight to the star, and microturbulent velocity of the gas
!!$ Returns: cooling of the gas in erg s^-1 (gas particle)^-1

  SUBROUTINE CalcCoolTot(ngas, Tempgas, JwCII, JwOI02, JwOI01, JwOI12, Ntostar, CoolTot)

!!$ Declare variables
!!$ Specify input and output
!!$ ngas    = density of gas in particles cm^-3
!!$ Tempgas = temperature of gas in K ! tgas used in pisco
!!$ Jw      = mean intensity in erg / ( s cm^2 sr cm^-1) for all transitions
!!$ Ntostar = column density of gas in line of sight to star in particles cm^-2
!!$ CoolTot = total cooling due to all cooling processes in erg s^-1 (gas particle)^-1
    REAL, INTENT(IN)  :: ngas , Tempgas, JwCII, JwOI02, JwOI01, JwOI12, Ntostar
    REAL, INTENT(OUT) :: CoolTot

!!$ Specify internal variables
!!$ CoolCII = cooling due to [CII] at 158 microns in erg s^-1 (gas particle)^-1
!!$ CoolOI  = cooling due to [OI] at 45, 63, 145 microns in erg s^-1 (gas particle)^-1
    REAL :: CoolCII, CoolOI

!!$ TODO: make all cooling subroutines modules.
!!$ TODO: make J the radiation field gg dependent on the process. Currently using J = gg(158 um)
    CALL CalcCoolCII(ngas = ngas, Tempgas = Tempgas, Jw = JwCII, Ntostar = Ntostar, CoolCII = CoolCII)
    CALL CalcCoolOI(ngas = ngas, Tempgas = Tempgas, Jw02 = JwOI02, Jw01 = JwOI01, Jw12 = JwOI12, Ntostar = Ntostar, CoolOI = CoolOI)

!!$ TODO: Sum over all other cooling processes too.
    CoolTot = CoolCII + CoolOI

  END SUBROUTINE CalcCoolTot
  


END MODULE ModCoolTot
